package com.zsd.android.camerax.view.activity

import android.Manifest
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.zsd.android.camerax.R
import com.zsd.android.camerax.model.MainModel
import com.zsd.android.camerax.presenter.MainPresenter
import com.zsd.android.camerax.view.IMainView
import com.zsd.android.camerax.view.fragment.HomeFragment
import com.zsd.android.common.BaseActivity
import com.zsd.android.common.utils.CameraEngine
import com.zsd.android.common.utils.MLog
import com.zsd.android.common.utils.PermissionHelper

class MainActivity : BaseActivity<IMainView, MainModel, MainPresenter>(), View.OnClickListener,
    IMainView {

    private var mainTv: TextView? = null
    private var mainFrame: FrameLayout? = null

    override fun layoutId(): Int {
        return R.layout.activity_main
    }

    override fun initPresenter(): MainPresenter {
        return MainPresenter(this)
    }

    override fun initView(savedInstanceState: Bundle?) {
        mainTv = findViewById(R.id.main_tv)
        mainFrame = findViewById(R.id.main_frame)
        mainTv?.setOnClickListener(this)

        val fManager = supportFragmentManager
        fManager.beginTransaction().add(
            R.id.main_frame,
            HomeFragment.newInstance()
        ).commit()

        var cameraEngine = CameraEngine.Builder().build()
    }

    override fun onClick(view: View?) {
        when(view?.id) {
            R.id.main_tv -> {
                var permission = PermissionHelper.getInstance(mContext)
                permission?.isPermission(this, arrayOf(Manifest.permission.CAMERA), 1)
            }
            else -> {

            }
        }
    }

    override fun failedView(msg: String, isRefresh: Boolean, tag: Int) {
        showToast(msg)
    }
}
